<?php


  // Author: Tomasz Durka
  // Date: 6th May 2007
  // Returns an HTML table from an array
    
    
  function table (array $array, array $params = array()) {
    
    # Param defaults
    $border = 1;
    $padding = 0;
    $spacing = 0;
    $header = false;
    
    
    # Params setup
    foreach ($params as $_name => $_value) {
      switch ($_name) {
        case 'border':
        case 'padding':
        case 'spacing':
        case 'header':
          $$_name = $_value;
          break;
      }
    }
    
    
    # Table draw
    $first_passed = false;
    $r = "<table border=\"{$border}\" cellpadding=\"{$padding}\" cellspacing=\"{$spacing}\">";
    foreach ($array as $arr_row) {
      if (!$first_passed) {
        if ($header === true) {
          $r .= "<tr>";
          foreach ($arr_row as $column_name => $field) {
            $r .= "<th>";
            $r .= Inflector::Humanize($column_name);
            $r .= "</th>";
            $first_passed = true;
          }
          $r .= "</tr>";
        }
      }
      $r .= "<tr>";
      foreach ($arr_row as $column_name => $field) {
        $r .= "<td>";
        $r .= $field;
        $r .= "</td>";
      }
      $r .= "</tr>";
    }
    $r .= "</table>";
    return $r;
  }

?>